package com.example.reptile.config;

import lombok.extern.log4j.Log4j2;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

import java.io.FileNotFoundException;

@Component
@Log4j2
public class ChromeConfig {
    static {
        String path = null;
        try {
            path = ResourceUtils.getFile("classpath:driver/chromedriver.exe").getPath();
        } catch (FileNotFoundException e) {
            log.error("谷歌驱动加载失败", e);
        }
        System.setProperty("webdriver.chrome.driver", path);
    }

    public static ChromeOptions getOptions() {
        ChromeOptions options = new ChromeOptions();
        //options.addArguments("--headless"); //无浏览器模式
        options.addArguments("--no-sandbox");// 为了让root用户也能执行
        // 优化参数
        options.addArguments("--disable-dev-shm-usage");
        options.addArguments("blink-settings=imagesEnabled=true");// 不加载图片, 提升速度
        options.addArguments("--disable-gpu");
        return options;
    }

}
